package com.zyh.lambda;

import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Author zyh
 * @Date 2024/8/16 9:04
 * @Description
 */

public class LambdaDemo1 {
    //使用lambda表达式删除集合中的元素
    @Test
    public void test3() {
//        List<Student> list=new ArrayList<>();
//        list.add(new Student("zyh",20,"11",new Date()));
//        list.add(new Student("zyh",21,"11",new Date()));
//        list.removeIf(item->item.getAge()==20);
//        list.forEach(System.out::println);
    }


    //使用lambda表达式遍历集合
    @Test
    public void test2() {
        List<Integer> list = Arrays.asList(3, 5, 4, 2, 1);
        list.forEach(item -> System.out.println(item));
        System.out.println("------------------");
        //使用lambda进行方法的调用
        list.forEach(System.out::println);
    }


    //使用lambda表达式创建线程
    @Test
    public void test1() {
        new Thread(() -> System.out.println(Thread.currentThread().getName() + "正在执行")).start();
        //使用线程池方法
        ExecutorService threadPool = Executors.newSingleThreadExecutor();
        threadPool.submit(() -> System.out.println(Thread.currentThread().getName() + "正在执行"));
        threadPool.shutdown();
    }
}
